from django.shortcuts import loader,get_object_or_404
from isa.models import CUser
def load_template(decoretor_arg):
    def _load_template(method):    
        def __load_template(*args,**kargs):
            
            template =loader.get_template(decoretor_arg+".html")
            
            sentinel = object()
            g = method.__globals__
            oldvalue  = g.get("template",sentinel)
            g['template'] = template
            try:
                res = method(*args,**kargs)
            finally:
                if oldvalue is sentinel:
                    del g['template']
                else:
                    g['template'] = oldvalue 
        
            return res
        return __load_template
    return _load_template


def current_user(request):
    return request.user

def get_current_c_user(request):
    if not request.user.is_active :
        return None
    return get_object_or_404(CUser,user=request.user)

class session_mixs :

    @staticmethod
    def set(request,**kargs):
        request.session.update(kargs)

    @staticmethod
    def get(request,*keys):
        try:
            if len(keys) == 1 :return request.session[key]
            return [request.session[key] for key in keys ]
        except NameError as e:
            return None


